package cn.hua.trip.base.domain;

import cn.hua.trip.base.util.JSONUtil;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Region extends BaseDomain{
    public static final int STATE_NORMAL = 0;//普通状态
    public static final int STATE_HOT = 1;//推荐状态

    private String name; //地区名

    private Long parentId; //上一级地区id

    private Integer state=STATE_NORMAL;//默认状态为普通状态

    public Map<String,Object> toMap(){
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("text",getName());
        map.put("lazyLoad",true);
        if (state==STATE_HOT) {
            map.put("tags",new String[]{"热门"});
        }
        map.put("id",getId());
        map.put("json",getJsonString());
        map.put("parentId",getParentId());
        return map;
    }

    public String getJsonString(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("name",name);
        map.put("parentId",parentId);
        map.put("state",state);

        return JSONUtil.toJSONString(map);
    }
}